package com.example.demo.controller;

import com.example.demo.pojo.Account;
import com.example.demo.result.Result;
import com.example.demo.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/user")
//@CrossOrigin//解决跨域问题，配置类里已经写了就不用这个注解
public class AccountController {

    @Autowired
    private AccountService accountService;

    @PostMapping("/login")
    public Result login(@RequestBody Account account){
        Map<String,Object> data=accountService.login(account);
        if(data!=null){
            return Result.success(data);
        }
        return Result.fail(20003,"用户名或密码错误");
    }

    @GetMapping("/info")
    public Result info(@RequestParam("token") String token){
        Map<String,Object> data=accountService.getUserInfo(token);
        if(data!=null){
            return Result.success(data);
        }
        return Result.fail(20003,"用户信息失效，请重新登录");
    }

    //退出
    @PostMapping("/logout")
    public Result<?> logout(){

        return Result.success();
    }
}
